In [1]:
import nibabel as nib
import numpy as np
In [2]:
from scipy.ndimage.measurements import label
from scipy.ndimage.morphology import generate_binary_structure
In [78]:
sim_img = image.load_img('/Users/dlurie/Dropbox/Projects/avalanche/avalanche/data/simdata_c1-c5_noise.nii.gz')
In [79]:
sim_data = sim_img.get_data()
In [80]:
sim_data.shape
Out[80]:
Connectivity default
In [81]:
labels = label(sim_data)
In [82]:
labels[0].max()
Out[82]:
In [83]:
affine = np.diag([1, 1, 1, 1])
labels_img = nib.Nifti1Image(labels[0], affine)
In [84]:
labels_img.to_filename('/Users/dlurie/Dropbox/Projects/avalanche/avalanche/data/simdata_c1-c5_labels_default.nii.gz')
Connectivity 4,4
In [3]:
struct_44 = generate_binary_structure(4,4)
In [109]:
labels_44 = label(sim_data, structure=struct_44)
In [110]:
labels_44[0].max()
Out[110]:
In [111]:
labels_44_img = nib.Nifti1Image(labels_44[0], affine)
In [112]:
labels_44_img.to_filename('/Users/dlurie/Dropbox/Projects/avalanche/avalanche/data/simdata_c1-c5_labels_44.nii.gz')
Connectivity 4,3
In [4]:
struct_43 = generate_binary_structure(4,3)
In [94]:
labels_43 = label(sim_data, structure=struct_43)
In [95]:
labels_43[0].max()
Out[95]:
In [96]:
labels_43_img = nib.Nifti1Image(labels_43[0], affine)
In [97]:
labels_43_img.to_filename('/Users/dlurie/Dropbox/Projects/avalanche/avalanche/data/simdata_c1-c5_labels_43.nii.gz')
Connectivity 4,2
In [98]:
struct_42 = generate_binary_structure(4,2)
In [99]:
labels_42 = label(sim_data, structure=struct_42)
In [100]:
labels_42[0].max()
Out[100]:
In [101]:
labels_42_img = nib.Nifti1Image(labels_42[0], affine)
In [102]:
labels_42_img.to_filename('/Users/dlurie/Dropbox/Projects/avalanche/avalanche/data/simdata_c1-c5_labels_42.nii.gz')
Connectivity 4,1
In [103]:
struct_41 = generate_binary_structure(4,1)
In [104]:
labels_41 = label(sim_data, structure=struct_41)
In [105]:
labels_41[0].max()
Out[105]:
In [106]:
labels_41_img = nib.Nifti1Image(labels_41[0], affine)
In [107]:
labels_41_img.to_filename('/Users/dlurie/Dropbox/Projects/avalanche/avalanche/data/simdata_c1-c5_labels_41.nii.gz')